﻿using System.Drawing;
using System.IO;

using Microsoft.WowAddonStudio.FrameXml.Formats.Mpq;
using Microsoft.WowAddonStudio.FrameXml.Services;
using Microsoft.WowAddonStudio.FrameXml.Services.Tests.Properties;
using NUnit.Framework;

namespace Microsoft.WowAddonStudio.FrameXml.Services.Tests
{
    [TestFixture]
    public class FrameXmlImageServiceTest
    {
        private const string mpqArchiveRelativePath = @"Data\enGB\locale-enGB.MPQ";
        private const string mpqBlpImagePath = @"Interface\Spellbook\Spellbook-Icon.blp";

        private string mpqArchivePath;

        [SetUp]
        public void SetUp()
        {
            if (!Directory.Exists(Settings.Default.WowBasePath))
                Assert.Ignore("Cannot run test. Please set the World of Warcraft base path.");

            mpqArchivePath = Path.Combine(Settings.Default.WowBasePath, mpqArchiveRelativePath);
        }

        [Test]
        public void GetImageTest()
        {
            using (var mpqArchive = new MpqArchive(mpqArchivePath))
            using (var resourceFileLoader = new ResourceFileLoader())
            using (var frameXmlImageService = new FrameXmlImageService(resourceFileLoader))
            {
                // Add WoW base path
                resourceFileLoader.BasePaths.Add(Settings.Default.WowBasePath);

                // Add MPQ archive
                resourceFileLoader.MpqArchives.Add(mpqArchive);

                // Try to get a BLP image from the MPQ
                Image blpImage = frameXmlImageService.GetImage(mpqBlpImagePath);

                Assert.IsNotNull(blpImage, "GetImage returned null.1");
                Assert.AreNotEqual(0, blpImage.Width, "GetImage return image with zero width.");
                Assert.AreNotEqual(0, blpImage.Height, "GetImage return image with zero height.");
            }
        }
    }
}
